package com.itheima.jobs;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.ClearOrderSettingService;
import com.itheima.utils.QiNiuUtil;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import redis.clients.jedis.JedisPool;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;

@Component
public class ClearOrderSetting {
    @Autowired
    JedisPool jedisPool;

    @Reference
    ClearOrderSettingService clearOrderSettingService;


    public void clearOrderSetting() {

        //先从数据库中查询出前两个月需要删除的数据
        //获取当前时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //得到日历
        Calendar calendar = Calendar.getInstance();
        //把当前时间赋给日历
        calendar.setTime(new Date());

        //获取前第三个月前的时间
        calendar.add(calendar.MONTH,-1);
        Date beforeTwoMouth3 = calendar.getTime();
        String format3 = sdf.format(beforeTwoMouth3);

        //获取前第一个月前的时间
        calendar.add(calendar.MONTH, -2);
        Date beforeTwoMouth1 = calendar.getTime();
        String format1 = sdf.format(beforeTwoMouth1);

        System.out.println(format3);
        System.out.println(format1);

        clearOrderSettingService.deleteByBeforeTwoOrderDate(format1, format3);

    }

}
